
#include "app_console.h"
#include "app_storage.h"
#include "console_wifi.h"

const static char *TAG = "console";



int AppConsole::sys_cmd_func(int argc, char **argv)
{
    uint8_t ssid[32];      /**< SSID of target AP. */
    uint8_t password[64];  /**< Password of target AP. */

    if(AppStorage::get(cfgPartitionData::ssid,ssid,sizeof(ssid)) == 0)
    {
        ESP_LOGE("AppStorage", "Get ssid err!");
    }
    if(AppStorage::get(cfgPartitionData::passwd,password,sizeof(password)) == 0)
    {
        ESP_LOGE("AppStorage", "Get passwd err!");
        AppStorage::set(cfgPartitionData::passwd,password,sizeof(password));
    }
    
    ESP_LOGI(TAG, "-------------------sys info start-------------------");
    ESP_LOGI(TAG, ">>>wifi info ->[%s][%s]",ssid,password);
    ESP_LOGI(TAG, "-------------------sys info end-------------------");
    return 0;
}

void AppConsole::sys_cmd_register(void)
{
   const esp_console_cmd_t cmd = {
         .command = "sys",
         .help = "Get the system info",
         .hint = NULL,
         .func = &AppConsole::sys_cmd_func,
      };
    ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
}

void AppConsole::cmd_register(void)
{
   AppConsole::sys_cmd_register();
   wifi_register();
}





